package cn.edu.jnu.booklistmainactivity;

import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

public class setting_Activity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);

        Toolbar mToolbar = (Toolbar) findViewById(R.id.settings_toolbar);
        setSupportActionBar(mToolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setTitle("Settings");
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
//在activity中启动加载SettingsFragment.java：
        if (savedInstanceState == null) {
            settings_Fragment settingsFragment = new settings_Fragment();
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.activity_setting_container, settingsFragment)
                    .commit();
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            //当您调用 setHomeButtonEnabled在您的工具栏上，Android 添加了自己的图标，并为其提供了一个内部 ID android.R.id.home .
            // 这始终是该主页按钮的标识符，您可以通过在选择菜单项时检查该 ID 来检查它是否被按下
            case android.R.id.home:
                finish();
                break;
            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }

}